package com.example.flowable.controller;

import com.example.flowable.model.Role;
import com.example.flowable.model.ResultDTO;
import com.example.flowable.service.RoleService;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping(value = "add")
    @ResponseBody
    public ResultDTO<Void> add(@RequestBody Role role) {
        roleService.addRole(role);
        return new ResultDTO<Void>().buildResultDTO(200,"sucess",null,null);
    }

    @RequestMapping(value = "list")
    @ResponseBody
    public ResultDTO<List<Role>> list() {
        List<Role> roleList = roleService.queryRoleList(new Role());
        return new ResultDTO<List<Role>>().buildResultDTO(200,"sucess", roleList, roleList.size());
    }

    @RequestMapping(value = "remove")
    @ResponseBody
    public ResultDTO<Void> remove(@RequestBody Role role) {
        roleService.deleteRole(role);
        return new ResultDTO<Void>().buildResultDTO(200,"sucess",null,null);
    }
}
